# -*- coding: cp1252 -*-

import gdata.projecthosting.client
import gdata.projecthosting.data
import gdata.gauth
import gdata.client
import atom.http_core
import atom.mock_http_core
import atom.core
import gdata.data
import gdata.test_config as conf
import time
import os

def authenticating_client(client, username, password):
    return client.client_login(
         username,
         password,
         source='your-client-name',
         service='code')

def create_issue(name, mail, bug):
    """Creates a new issue on Google Code."""
    client = gdata.projecthosting.client.ProjectHostingClient()
    owner = 'labtoolssoftware@googlemail.com'
    password = 'SytcF!]&'
    authenticating_client(client, owner, password)

    project_name = 'sifi3'
    
    date = time.strftime("%d.%m.%Y um %H:%M:%S")
    
    report = 'Name: ' + str(name) + '\n' + 'E-Mail: ' + str(mail) + '\n\n' + str(bug) + '\n\n'
    
    if os.path.exists(os.getcwd()+ '\si-Fi3.exe.log'):
        f_log = open(os.getcwd()+ '\si-Fi3.exe.log')
        log = f_log.read()
        report = report + str(log)
        f_log.close()
    
    fileencoding = "iso-8859-1"
    report = unicode(report, fileencoding)
        
    created = client.add_issue(project_name,
                               'User Report ' + str(date),
                                report,
                                owner,
                                labels=['Type-UserReport'])
    
    return created

#create_issue('test', 'test', 'test')